package com.wenlin.myproduction.binder;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.wenlin.myproduction.R;
import com.wenlin.myproduction.bean.GameOption;
import com.wenlin.myproduction.util.TypeData;
import com.wenlin.myproduction.util.TypeDataNames;
import com.wenlin.myproduction.util.UI;

import org.greenrobot.eventbus.EventBus;

import me.drakeet.multitype.ItemViewBinder;

/**
 * @author 文琳
 * @Email 377979485@qq.com
 * @desc
 * @time 2022-09-03 星期六 13:38
 */
public class GameOptionBinder extends ItemViewBinder<GameOption, GameOptionBinder.GameOptionHolder> {


    @NonNull
    @Override
    protected GameOptionHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        return new GameOptionHolder(inflater.inflate(R.layout.item_game_option, parent, false));
    }

    @Override
    protected void onBindViewHolder(@NonNull GameOptionHolder holder, @NonNull GameOption item) {
        UI.setText(holder.tvName, item.getName());
        UI.setImageResource(holder.ivBg, item.isSelected() ? R.mipmap.bg_selected : R.mipmap.bg_normal);
        UI.setOnClickListener(holder.ivBg,
                (view) -> EventBus.getDefault().post(new TypeData<>(TypeDataNames.clickGameOption, item)));
    }

    static class GameOptionHolder extends RecyclerView.ViewHolder {
        TextView tvName;
        ImageView ivBg;

        public GameOptionHolder(@NonNull View itemView) {
            super(itemView);
            tvName = itemView.findViewById(R.id.tv_name);
            ivBg = itemView.findViewById(R.id.iv);
        }
    }
}
